<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">
<ui:composition template="template.xhtml">
	<ui:define name="content">
		<h:form id="form01">
			<p:panel header="Treatment Record List"
				rendered="#{mainMenuControler.hasUserRole('admin') || mainMenuControler.hasUserRole('treatment_record')}"
				style="text-align:center">
				<div style="float: left">
					<p:commandButton id="addNewBtn" ajax="true"
						value="#{dictionaryControler.dictionary['Add']} #{dictionaryControler.dictionary['TreatmentRecord']}:"
						actionListener="#{treatmentRecordListControler.startAddTreatmentRecord}"
						icon="ui-icon-plus" update=":form04:detailDialog,:form01:message" />
				</div>
				<br />
				<br />
				<p:messages id="message" />
				<p:dataTable id="treatmentRecordTable" widgetVar="widgetVar_w"
					value="#{treatmentRecordListControler.treatmentRecordList}"
					var="treatmentRecord" rows="15" paginator="true"
					filteredValue="#{treatmentRecordListControler.filteredTerms}"
					paginatorAlwaysVisible="true" paginatorPosition="bottom"
					first="#{treatmentRecordListControler.first}"
					paginatorTemplate="{PreviousPageLink} {CurrentPageReport} {NextPageLink}">
					<p:column style="width:10%"
						headerText="#{dictionaryControler.dictionary['Seq']}">
						<h:outputText value="#{treatmentRecord.seq}" />
					</p:column>
					<p:column style="width:10%"
						filterBy="#{treatmentRecord.patientName}"
						filterMatchMode="contains"
						headerText="#{dictionaryControler.dictionary['Patient']} #{dictionaryControler.dictionary['Name']}">
						<h:outputText value="#{treatmentRecord.patientName}" />
					</p:column>
					<p:column style="width:10%"
						filterBy="#{treatmentRecord.doctorName}"
						filterMatchMode="contains"
						headerText="#{dictionaryControler.dictionary['Doctor']} #{dictionaryControler.dictionary['Name']}">
						<h:outputText value="#{treatmentRecord.doctorName}" />
					</p:column>
					<p:column style="width:10%"
						headerText="#{dictionaryControler.dictionary['Symptom']}">
						<h:outputText value="#{treatmentRecord.symptom}" />
					</p:column>
					<p:column style="width:10%"
						headerText="#{dictionaryControler.dictionary['Comment']}">
						<h:outputText value="#{treatmentRecord.doctorComment}" />
					</p:column>
					<p:column style="width:10%"
						headerText="#{dictionaryControler.dictionary['Date']}">
						<h:outputText value="#{treatmentRecord.treatDate}">
							<f:convertDateTime pattern="yyyy-MM-dd" timeZone="GMT+8" />
						</h:outputText>
					</p:column>
					<p:column style="width:3%"
						headerText="#{dictionaryControler.dictionary['Edit']}">
						<p:commandButton id="editButton"
							update=":form04:detailDialog_1,:form01:message"
							action="#{treatmentRecordListControler.startEditTreatmentRecord}"
							icon="ui-icon-pencil">
							<f:setPropertyActionListener value="#{treatmentRecord}"
								target="#{treatmentRecordListControler.selectedTreatmentRecord}" />
						</p:commandButton>
					</p:column>
					<p:column style="width:3%"
						headerText="#{dictionaryControler.dictionary['Delete']}">
						<p:commandButton id="deleteButton" ajax="true"
							update=":form01:treatmentRecordTable"
							oncomplete="PF('widgetVar_w').clearFilters();"
							action="#{treatmentRecordListControler.deleteTreatmentRecord()}"
							icon="ui-icon-close" style="margin-right:5px">
							<f:setPropertyActionListener value="#{treatmentRecord}"
								target="#{treatmentRecordListControler.selectedTreatmentRecord}" />
							<p:confirm
								header="#{dictionaryControler.dictionary['Confirmation']}"
								message="#{dictionaryControler.dictionary['Are you sure']}?"
								icon="ui-icon-alert" />
						</p:commandButton>
					</p:column>
				</p:dataTable>
			</p:panel>
			<h:outputText value="Access Denied, please contact the administrator"
				rendered="#{!(mainMenuControler.hasUserRole('admin') || mainMenuControler.hasUserRole('treatment_record'))}"
				style="width:100%; height:50%; text-align:center; font-size:150% !important;position:absolute; margin-left:0; margin-right:0; margin-top:0;margin-bottom:0" />
		</h:form>
	</ui:define>

	<ui:define name="dialog">
		<h:form id="form04">
			<p:dialog id="detailDialog" widgetVar="detailDialog_w" modal="true"
				showEffect="fade" resizable="false" draggable="true"
				closable="false" visible="#{treatmentRecordListControler.addMode}"
				header="#{dictionaryControler.dictionary['TreatmentRecord Add']}">
				<p:focus context="detailDialog" for="addBtn" />
				<p:panelGrid columns="2">
					<p:outputLabel for="patientNameCombo"
						value="#{dictionaryControler.dictionary['Patient Name']}" />
					<p:selectOneMenu id="patientNameCombo"
						rendered="#{treatmentRecordListControler.addMode}"
						value="#{treatmentRecordListControler.newTreatmentRecord.patientSeq}"
						style="width:98%" editable="false">
						<f:selectItems value="#{treatmentRecordListControler.patientList}"
							var="patient" itemLabel="#{patient.name}"
							itemValue="#{patient.seq}" />
					</p:selectOneMenu>

					<p:outputLabel for="doctorNameCombo"
						value="#{dictionaryControler.dictionary['Doctor Name']}" />
					<p:selectOneMenu id="doctorNameCombo"
						rendered="#{treatmentRecordListControler.addMode}"
						value="#{treatmentRecordListControler.newTreatmentRecord.doctorSeq}"
						style="width:98%" editable="false">
						<f:selectItems value="#{treatmentRecordListControler.doctorList}"
							var="doctor" itemLabel="#{doctor.name}" itemValue="#{doctor.seq}" />
					</p:selectOneMenu>

					<h:outputText
						value="#{dictionaryControler.dictionary['Treatment Date']}" />
					<h:outputText
						value="#{treatmentRecordListControler.newTreatmentRecord.treatDate}">
						<f:convertDateTime pattern="yyyy-MM-dd" timeZone="GMT+8" />
					</h:outputText>

					<h:outputText value="#{dictionaryControler.dictionary['Symptom']}" />
					<p:inputTextarea rows="3" cols="23"
						value="#{treatmentRecordListControler.newTreatmentRecord.symptom}"
						maxlength="100" required="true"
						rendered="#{treatmentRecordListControler.addMode}"
						requiredMessage="#{dictionaryControler.dictionary['Symptom']} {dictionaryControler.dictionary['Required']}" />
					<h:outputText value="#{dictionaryControler.dictionary['Comment']}" />
					<p:inputTextarea rows="3" cols="23"
						value="#{treatmentRecordListControler.newTreatmentRecord.doctorComment}"
						maxlength="100" required="true"
						rendered="#{treatmentRecordListControler.addMode}"
						requiredMessage="#{dictionaryControler.dictionary['Comment']} {dictionaryControler.dictionary['Required']}" />
				</p:panelGrid>
				<br />
				<div style="text-align: right">
					<p:commandButton id="addBtn"
						value="#{dictionaryControler.dictionary['Add']}" ajax="true"
						actionListener="#{treatmentRecordListControler.addNewTreatmentRecord}"
						update="detailDialog,:form01:treatmentRecordTable"
						oncomplete="PF('widgetVar_w').clearFilters();"
						style="margin-right:5px" />
					<p:commandButton id="cancelBtn"
						value="#{dictionaryControler.dictionary['Cancel']}" ajax="true"
						actionListener="#{treatmentRecordListControler.cancelAddTreatmentRecord}"
						update="detailDialog" immediate="true" />
				</div>
				<p:messages />
			</p:dialog>
			<p:dialog id="detailDialog_1" widgetVar="detailDialog_e" modal="true"
				resizable="false" draggable="true" closable="false"
				visible="#{treatmentRecordListControler.editMode}"
				header="#{dictionaryControler.dictionary['Edit']} #{dictionaryControler.dictionary['TreatmentRecord']}"
				style="text-align:center">
				<p:panelGrid columns="2">
					<p:outputLabel for="patientNameCombo_1"
						value="#{dictionaryControler.dictionary['Patient Name']}" />
					<p:selectOneMenu id="patientNameCombo_1"
						rendered="#{treatmentRecordListControler.editMode}"
						value="#{treatmentRecordListControler.selectedTreatmentRecord.patientSeq}"
						style="width:98%" editable="false">
						<f:selectItem itemLabel="Select one" itemValue="-1" />
						<f:selectItems value="#{treatmentRecordListControler.patientList}"
							var="patient" itemLabel="#{patient.name}"
							itemValue="#{patient.seq}" />
					</p:selectOneMenu>

					<p:outputLabel for="doctorNameCombo_1"
						value="#{dictionaryControler.dictionary['Doctor Name']}" />
					<p:selectOneMenu id="doctorNameCombo_1"
						rendered="#{treatmentRecordListControler.editMode}"
						value="#{treatmentRecordListControler.selectedTreatmentRecord.doctorSeq}"
						editable="false" style="width:98%">
						<f:selectItem itemLabel="Select one" itemValue="-1" />
						<f:selectItems value="#{treatmentRecordListControler.doctorList}"
							var="doctor" itemLabel="#{doctor.name}" itemValue="#{doctor.seq}" />
					</p:selectOneMenu>

					<h:outputText
						value="#{dictionaryControler.dictionary['Treatment Date']}" />
					<h:outputText
						value="#{treatmentRecordListControler.selectedTreatmentRecord.treatDate}">
						<f:convertDateTime pattern="yyyy-MM-dd" timeZone="GMT+8" />
					</h:outputText>
					<h:outputText value="#{dictionaryControler.dictionary['Symptom']}" />
					<p:inputTextarea rows="3" cols="23"
						value="#{treatmentRecordListControler.selectedTreatmentRecord.symptom}"
						maxlength="100" required="true"
						rendered="#{treatmentRecordListControler.editMode}"
						requiredMessage="#{dictionaryControler.dictionary['Symptom']} {dictionaryControler.dictionary['Required']}" />
					<h:outputText value="#{dictionaryControler.dictionary['Comment']}" />
					<p:inputTextarea rows="3" cols="23"
						value="#{treatmentRecordListControler.selectedTreatmentRecord.doctorComment}"
						maxlength="100" required="true"
						rendered="#{treatmentRecordListControler.editMode}"
						requiredMessage="#{dictionaryControler.dictionary['Comment']} {dictionaryControler.dictionary['Required']}" />
				</p:panelGrid>
				<br />
				<div style="text-align: right">
					<p:commandButton id="saveBtn_1"
						value="#{dictionaryControler.dictionary['Save']}" ajax="true"
						action="#{treatmentRecordListControler.saveEditTreatmentRecord}"
						update=":form01:treatmentRecordTable,detailDialog_1"
						style="margin-right:5px" />
					<p:commandButton id="cancelBtn_1"
						value="#{dictionaryControler.dictionary['Cancel']}" ajax="true"
						action="#{treatmentRecordListControler.cancelEditTreatmentRecord}"
						immediate="true" update="detailDialog_1" />
					<p:messages />
				</div>
			</p:dialog>
		</h:form>
	</ui:define>
</ui:composition>
</html>